
#ifndef __TOOL_H__
#define __TOOL_H__

#include "config.h"


#include "global.h"

#include "memoryallot.h"


#define DelayUs(time)               Ddl_Delay1us(time)
#define DelayMs(time)               Ddl_Delay1ms(time)

uint16 ModbusCRC(uint8 *ptr, uint16 len);
//void DelayUs(uint16 time);
//void DelayMs(uint16 time);
void memfcpy(uint8 *ptr, int len);
void memcpyAndf(uint8 *dst, uint8 *src, int len);
uint8 BcdJudge(uint8 *ptr, uint16 len);
void SeparateBcd(uint8 *ptr1, uint8 *ptr2, uint8 len);
uint8 DataEqualCmp(uint8 *ptr, uint8 dat, uint8 len);
uint8 CmpLargeSmall(uint8 *ptr1, uint8 *ptr2, uint8 num);
uint8 BcdToHexOne(uint8 bcd);
uint8 HexToBcdOne(uint8 hex);
void HexToBcdMul(uint8* hex, uint16 len);
void BcdToHexMul(uint8 * bcd, uint16 len);
void HexToBcd(uint32 hex, uint8 *bcd, uint8 len);
uint16 CRCLong(uint16 crc,uint8 *ptr, uint16 len);
uint32 BcdToHex(uint8 *bcd, uint8 len);
uint8 AsciiJudge(uint8 *ptr, uint16 len);
void memfcpyBit(uint8 *ptr, int len);
uint8 AccountStrintLen(uint8 *ptr, uint32 len);
void Bcd2Ascii(uint8 *bcd, uint8 *ascii, uint8 bcdlen);
void BcdToHex64(uint8 *bcd, uint8 bcdlen, uint8 *hex, uint8 hexlen);

uint8 AccountSum(uint8 *ptr, int len);
void ComRead33Data(uint8 *p,uint8 len);
void ComWrite33Data(uint8 *ptr, uint8 len);


void Exchange(unsigned char *BufA, unsigned char *BufB, unsigned char Len );
void Inverse( unsigned char *Buf, unsigned char Len );

int32 Byte2Int(uint8* byte);
int16 Byte2Short(uint8* byte);
uint32 Byte2uInt(uint8* byte);
uint16 Byte2uShort(uint8* byte);
void Int2Byte(uint32 datatemp,uint8* Buff);
void Short2Byte(uint16 datatemp,uint8* Buff);
unsigned char GetApduByte( unsigned char *pBuf );
unsigned char PutApduByte( unsigned char *pBuf, unsigned char Value );
unsigned char MoveByte( unsigned char *MoveBuf, unsigned int Get, unsigned int Put );
unsigned char CopyApdu( unsigned char *Des, unsigned char *Src, unsigned int Len );
unsigned char CopyApduInv( unsigned char *Des, unsigned char *Src, unsigned int Len );
unsigned char MoveForword( unsigned char *MoveBuf, unsigned int Len, unsigned int Total );
unsigned char MoveBackword( unsigned char *MoveBuf, unsigned int Len, unsigned int Total );
void Xor_Data( unsigned char *BufA, unsigned char *BufB, uint16 Num );

void ByteArrayToString(uint8 *ptr1, uint8 *ptr2, uint8 ptr1len);

#endif /* __TOOL_H_ */
